<template>
	<view class="columnbox wdh-100 content">
		<view class="rowbox wdh-100">
			<image src="/static/img/logo.jpeg" mode="aspectFill" class="logo"></image>
		</view>
		<view class="title">欢迎来到摩卡洗车</view>
		<button class="rowbox log-btn def-bgcol" open-type="getPhoneNumber"
			@getphonenumber="getPhoneNumber">立即登录</button>
			<!-- <button class="rowbox log-btn def-bgcol" open-type="getPhoneNumber"
				@getphonenumber="panduanLogin">立即登录</button> -->
	</view>
	<!--  <view>
        <button @click="toLog">登录</button>
        <button type="primary" class="login-btn" open-type="getPhoneNumber"
            @getphonenumber="getPhoneNumber">绑定手机号</button>
        <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">11</button>
    </view> -->
</template>

<script>
	export default {
		data() {
			return {

			};
		},
		methods: {
			getPhoneNumber(e) {
				console.log(e)
				console.log(e)
				if (e.detail.code) {
					uni.showLoading({
						title: '正在登录'
					})
					this.$req.get('/xcx/user/getPhone', {
						xcxCode: e.detail.code,
						// appid: 'wxceac3fa1d6fa5ea4',
						// clientId: 'be7052a7e4f802c20df10a8d131adb12',
						// grantType: 'xcx'
					}).then(res => {
						console.log(res)
						this.toLog(res.data.data.phoneNumber)
					})
				} else {}
			},
			toLog(phoneNumber) {
				console.log("获取手机号" + phoneNumber)
				uni.login({
					provider: 'weixin',
					success: (res) => {
						this.$req.post('/auth/login', {
							xcxCode: res.code,
							appid: 'wxceac3fa1d6fa5ea4',
							clientId: 'be7052a7e4f802c20df10a8d131adb12',
							grantType: 'xcx',
							phone: phoneNumber
						}).then(res => {
							uni.setStorageSync('token', res.data.data.access_token)
							this.$store.dispatch('actionsHandleTokenChange', res.data.data
								.access_token);
							this.getUserInfo();
						})
					}
				})
			},
			panduanLogin(){
				uni.login({
					provider: 'weixin',
					success: (res) => {
						console.log(res)
						this.$req.post('/auth/login', {
							xcxCode: res.code,
							appid: 'wxceac3fa1d6fa5ea4',
							clientId: 'be7052a7e4f802c20df10a8d131adb12',
							grantType: 'xcx',
							// phone: '18211685248'
						}).then(res => {
							console.log(res)
						})
					}
				})
			
			},
			getUserInfo() {
				this.$req.get('/xcx/user/getInfo').then(res => {
					uni.hideLoading()
					uni.setStorageSync('userInfo', res.data.data)
					// console.log(res)
					// console.log(res.data.data)
					this.$store.dispatch('actionsHandleUserInfoChange', res
						.data.data);
					this.$store.dispatch('actionsHandleIsLoginChange',
						true);
					uni.navigateBack()
					// uni.showModal({
					// 	title: '登录成功',
					// 	complete: () => {
					// 		uni.requestSubscribeMessage({
					// 			tmplIds: [
					// 				'367jNYYM4UKrQ7xzhqLz-Mt8-UeJvpa5FlQ50DZ_4dM',
					// 				'S7dHsb73bp5orqZAZp-fc-1gEqVeo9BVfAT3p5aYPiQ'
					// 			],
					// 			success(res) {},
					// 			fail(errMessage) {
					// 				console.log("订阅消息 失败 ", errMessage);
					// 			},
					// 			complete: errMessage => {

					// 			}
					// 		})
					// 	}
					// })
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.content {
		padding: 100rpx 65rpx;
	}

	.logo {
		width: 140rpx;
		height: 140rpx;
		border-radius: 10rpx;
	}

	.title {
		margin-top: 29rpx;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 40rpx;
		color: #0E0E0E;
		margin-bottom: 140rpx;
	}

	.one-info {
		width: 100%;
		height: 105rpx;
		// box-shadow: 0px 2rpx 20rpx 0px #E6E8EE;
		border-radius: 10rpx;
		border: #E6E8EE solid 1px;
		padding: 0 32rpx;

		image {
			width: 40rpx;
			height: 40rpx;
			margin-right: 32rpx;
		}
	}

	.phone-input,
	.code-input {
		font-size: 28rpx;
		color: #0E0E0E;
		font-family: PingFang SC;
		text-align: left;
		width: calc(100% - 120rpx);
		border-left: #C5CDD4 solid 1px;
		padding-left: 40rpx;
	}

	.code-input {
		width: calc(100% - 300rpx);
	}

	.code-box {
		margin-left: 20rpx;
		width: 174rpx;
		height: 65rpx;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 24rpx;
		color: #fff;
		border-radius: 100rpx;
	}

	.reg-title {
		justify-content: flex-start;
		margin-top: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #00b6b2;
	}

	.log-btn {
		margin-top: 100rpx;
		width: 612rpx;
		height: 105rpx;
		border-radius: 20rpx;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 30rpx;
		color: #fff;
	}
</style>